package io.xccit.model.common.result;

import lombok.*;

/**
 * @author CH_ywx
 * @version 1.0
 * @create 2025/6/4
 * <p>统一资源返回对象</p>
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class AjaxResult<T> {

    private Integer code;
    private String message;
    private T data;

    public static <T> AjaxResult<T> success() {
        return new AjaxResult<>(200, "操作成功", null);
    }

    public static <T> AjaxResult<T> success(T data) {
        if (data != null) {
            return new AjaxResult<>(200, "操作成功", data);
        }
        return new AjaxResult<>(200, "操作成功", null);
    }

    public static <T> AjaxResult<T> error(String message) {
        return new AjaxResult<>(500, message, null);
    }

    public static <T> AjaxResult<T> error(Integer code, String message) {
        return new AjaxResult<>(code, message, null);
    }
}
